25. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2021-05-13 09:08:39 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

25.1 Files compared

#LocationFileLast Modified
1/Applications/Ampps/www/Porto 3.2.2/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterPrice.php2020-06-26 11:11:14 +0000
2/Applications/Ampps/www/Porto v4.0.0/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterPrice.php2020-11-17 05:51:58 +0000

25.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged5536
Changed48
Inserted00
Removed00

25.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

25.4 Active regular expressions

No regular expressions were active.

25.5 Comparison detail

1 <?php 1 <?php
2 /** 2 /**
3  * Mageplaza 3  * Mageplaza
4  * 4  *
5  * NOTICE OF LICENSE 5  * NOTICE OF LICENSE
6  * 6  *
7  * This source file is subject to the Mageplaza.com license that is 7  * This source file is subject to the Mageplaza.com license that is
8  * available through the world-wide-web at this URL: 8  * available through the world-wide-web at this URL:
9  * https://www.mageplaza.com/LICENSE.txt 9  * https://www.mageplaza.com/LICENSE.txt
10  * 10  *
11  * DISCLAIMER 11  * DISCLAIMER
12  * 12  *
13  * Do not edit or add to this file if you wish to upgrade this extension to newer 13  * Do not edit or add to this file if you wish to upgrade this extension to newer
14  * version in the future. 14  * version in the future.
15  * 15  *
16  * @category    Mageplaza 16  * @category    Mageplaza
17  * @package     Mageplaza_LayeredNavigation 17  * @package     Mageplaza_LayeredNavigation
18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/) 18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
19  * @license     https://www.mageplaza.com/LICENSE.txt 19  * @license     https://www.mageplaza.com/LICENSE.txt
20  */ 20  */
21  21 
22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; 22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter;
23  23 
24 use Magento\Catalog\Model\Layer as LayerCatalog; 24 use Magento\Catalog\Model\Layer as LayerCatalog;
25 use Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory; 25 use Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory;
26 use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory; 26 use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory;
27 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; 27 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
28 use Magento\Catalog\Model\Layer\Filter\ItemFactory; 28 use Magento\Catalog\Model\Layer\Filter\ItemFactory;
29 use Magento\Catalog\Model\ResourceModel\Layer\Filter\Price as CatalogPrice; 29 use Magento\Catalog\Model\ResourceModel\Layer\Filter\Price as CatalogPrice;
30 use Magento\CatalogSearch\Model\Layer\Filter\Price as AbstractFilter; 30 use Magento\CatalogSearch\Model\Layer\Filter\Price as AbstractFilter;
31 use Magento\Customer\Model\Session; 31 use Magento\Customer\Model\Session;
32 use Magento\Framework\App\RequestInterface; 32 use Magento\Framework\App\RequestInterface;
33 use Magento\Framework\Exception\LocalizedException; 33 use Magento\Framework\Exception\LocalizedException;
34 use Magento\Framework\Exception\StateException; 34 use Magento\Framework\Exception\StateException;
35 use Magento\Framework\Pricing\PriceCurrencyInterface; 35 use Magento\Framework\Pricing\PriceCurrencyInterface;
36 use Magento\Framework\Search\Dynamic\Algorithm; 36 use Magento\Framework\Search\Dynamic\Algorithm;
37 use Magento\Store\Model\StoreManagerInterface; 37 use Magento\Store\Model\StoreManagerInterface;
38 use Magento\Tax\Helper\Data as TaxHelper; 38 use Magento\Tax\Helper\Data as TaxHelper;
39 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; 39 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper;
40 use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection; 40 use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection;
41  41 
42 /** 42 /**
43  * Class Price 43  * Class Price
44  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter 44  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter
45  */ 45  */
46 class Price extends AbstractFilter 46 class Price extends AbstractFilter
47 { 47 {
48     /** @var LayerHelper */ 48     /** @var LayerHelper */
49     protected $_moduleHelper; 49     protected $_moduleHelper;
50  50 
51     /** @var array|null Filter value */ 51     /** @var array|null Filter value */
52     protected $_filterVal = null; 52     protected $_filterVal = null;
53  53 
54     /** @var TaxHelper */ 54     /** @var TaxHelper */
55     protected $_taxHelper; 55     protected $_taxHelper;
56  56 
57     /** @var LayerCatalog\Filter\DataProvider\Price */ 57     /** @var LayerCatalog\Filter\DataProvider\Price */
58     private $dataProvider; 58     private $dataProvider;
59  59 
60     /** @var PriceCurrencyInterface */ 60     /** @var PriceCurrencyInterface */
61     private $priceCurrency; 61     private $priceCurrency;
62  62 
63     /** 63     /**
64      * @param ItemFactory $filterItemFactory 64      * @param ItemFactory $filterItemFactory
65      * @param StoreManagerInterface $storeManager 65      * @param StoreManagerInterface $storeManager
66      * @param LayerCatalog $layer 66      * @param LayerCatalog $layer
67      * @param DataBuilder $itemDataBuilder 67      * @param DataBuilder $itemDataBuilder
68      * @param CatalogPrice $resource 68      * @param CatalogPrice $resource
69      * @param Session $customerSession 69      * @param Session $customerSession
70      * @param Algorithm $priceAlgorithm 70      * @param Algorithm $priceAlgorithm
71      * @param PriceCurrencyInterface $priceCurrency 71      * @param PriceCurrencyInterface $priceCurrency
72      * @param AlgorithmFactory $algorithmFactory 72      * @param AlgorithmFactory $algorithmFactory
73      * @param PriceFactory $dataProviderFactory 73      * @param PriceFactory $dataProviderFactory
74      * @param TaxHelper $taxHelper 74      * @param TaxHelper $taxHelper
75      * @param LayerHelper $moduleHelper 75      * @param LayerHelper $moduleHelper
76      * @param array $data 76      * @param array $data
77      */ 77      */
78     public function __construct( 78     public function __construct(
79         ItemFactory $filterItemFactory, 79         ItemFactory $filterItemFactory,
80         StoreManagerInterface $storeManager, 80         StoreManagerInterface $storeManager,
81         LayerCatalog $layer, 81         LayerCatalog $layer,
82         DataBuilder $itemDataBuilder, 82         DataBuilder $itemDataBuilder,
83         CatalogPrice $resource, 83         CatalogPrice $resource,
84         Session $customerSession, 84         Session $customerSession,
85         Algorithm $priceAlgorithm, 85         Algorithm $priceAlgorithm,
86         PriceCurrencyInterface $priceCurrency, 86         PriceCurrencyInterface $priceCurrency,
87         AlgorithmFactory $algorithmFactory, 87         AlgorithmFactory $algorithmFactory,
88         PriceFactory $dataProviderFactory, 88         PriceFactory $dataProviderFactory,
89         TaxHelper $taxHelper, 89         TaxHelper $taxHelper,
90         LayerHelper $moduleHelper, 90         LayerHelper $moduleHelper,
91         array $data = [] 91         array $data = []
92     ) { 92     ) {
93         parent::__construct( 93         parent::__construct(
94             $filterItemFactory, 94             $filterItemFactory,
95             $storeManager, 95             $storeManager,
96             $layer, 96             $layer,
97             $itemDataBuilder, 97             $itemDataBuilder,
98             $resource, 98             $resource,
99             $customerSession, 99             $customerSession,
100             $priceAlgorithm, 100             $priceAlgorithm,
101             $priceCurrency, 101             $priceCurrency,
102             $algorithmFactory, 102             $algorithmFactory,
103             $dataProviderFactory, 103             $dataProviderFactory,
104             $data 104             $data
105         ); 105         );
106  106 
107         $this->priceCurrency = $priceCurrency; 107         $this->priceCurrency = $priceCurrency;
108         $this->dataProvider  = $dataProviderFactory->create(['layer' => $this->getLayer()]); 108         $this->dataProvider  = $dataProviderFactory->create(['layer' => $this->getLayer()]);
109         $this->_moduleHelper = $moduleHelper; 109         $this->_moduleHelper = $moduleHelper;
110         $this->_taxHelper    = $taxHelper; 110         $this->_taxHelper    = $taxHelper;
111     } 111     }
112  112 
113     /** 113     /**
114      * @inheritdoc 114      * @inheritdoc
115      */ 115      */
116     public function apply(RequestInterface $request) 116     public function apply(RequestInterface $request)
117     { 117     {
118         if (!$this->_moduleHelper->isEnabled()) { 118         if (!$this->_moduleHelper->isEnabled()) {
119             return parent::apply($request); 119             return parent::apply($request);
120         } 120         }
121  121 
122         /** Filter must be string: $fromPrice-$toPrice */ 122         /** Filter must be string: $fromPrice-$toPrice */
123         $filter = $request->getParam($this->getRequestVar()); 123         $filter = $request->getParam($this->getRequestVar());
124         if (!$filter || is_array($filter)) { 124         if (!$filter || is_array($filter)) {
125             return $this; 125             return $this;
126         } 126         }
127         $filterParams = explode(',', $filter); 127         $filterParams = explode(',', $filter);
128         $filter       = $this->dataProvider->validateFilter($filterParams[0]); 128         $filter       = $this->dataProvider->validateFilter($filterParams[0]);
129         if (!$filter) { 129         if (!$filter) {
130             return $this; 130             return $this;
131         } 131         }
132  132 
133         $this->dataProvider->setInterval($filter); 133         $this->dataProvider->setInterval($filter);
134         $priorFilters = $this->dataProvider->getPriorFilters($filterParams); 134         $priorFilters = $this->dataProvider->getPriorFilters($filterParams);
135         if ($priorFilters) { 135         if ($priorFilters) {
136             $this->dataProvider->setPriorIntervals($priorFilters); 136             $this->dataProvider->setPriorIntervals($priorFilters);
137         } 137         }
138  138 
139         [$from, $to] = $this->_filterVal = $filter; 139         list($from, $to) = $this->_filterVal = $filter;
140  140 
141         $this->getLayer()->getProductCollection()->addFieldToFilter('price', [ 141         $this->getLayer()->getProductCollection()->addFieldToFilter('price', [
142             'from' => $from / $this->getCurrencyRate(), 142             'from' => $from / $this->getCurrencyRate(),
143             'to'   => $to / $this->getCurrencyRate() 143             'to'   => $to / $this->getCurrencyRate()
144         ]); 144         ]);
145  145 
146         $this->getLayer()->getState()->addFilter( 146         $this->getLayer()->getState()->addFilter(
147             $this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter) 147             $this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)
148         ); 148         );
149  149 
150         return $this; 150         return $this;
151     } 151     }
152  152 
153     /** 153     /**
154      * @inheritdoc 154      * @inheritdoc
155      */ 155      */
156     protected function _renderRangeLabel($fromPrice, $toPrice
)
 156     protected function _renderRangeLabel($fromPrice, $toPrice, $isLast = false)
157     { 157     {
158         if (!$this->_moduleHelper->isEnabled()) { 158         if (!$this->_moduleHelper->isEnabled()) {
159             return parent::_renderRangeLabel($fromPrice, $toPrice); 159             return parent::_renderRangeLabel($fromPrice, $toPrice);
160         } 160         }
161         $formattedFromPrice = $this->priceCurrency->format($fromPrice); 161         $formattedFromPrice = $this->priceCurrency->format($fromPrice);
162         if ($toPrice === '') { 162         if ($toPrice === '') {
163             return __('%1 and above', $formattedFromPrice); 163             return __('%1 and above', $formattedFromPrice);
164         } 164         }
165  165 
166         if ($fromPrice === $toPrice && $this->dataProvider->getOnePriceIntervalValue()) { 166         if ($fromPrice === $toPrice && $this->dataProvider->getOnePriceIntervalValue()) {
167             return $formattedFromPrice; 167             return $formattedFromPrice;
168         } 168         }
169  169 
170         return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice)); 170         return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
171     } 171     }
172  172 
173     /** 173     /**
174      * Price Slider Configuration 174      * Price Slider Configuration
175      * 175      *
176      * @return array 176      * @return array
177      */ 177      */
178     public function getSliderConfig() 178     public function getSliderConfig()
179     { 179     {
180         /** @var Collection $productCollection */ 180         /** @var Collection $productCollection */
181         $productCollection = $this->getLayer()->getProductCollection(); 181         $productCollection = $this->getLayer()->getProductCollection();
182  182 
183         if ($this->_filterVal) { 183         if ($this->_filterVal) {
184             /** @type Collection $productCollectionClone */ 184             /** @type Collection $productCollectionClone */
185             $productCollection = $productCollection->getCollectionClone() 185             $productCollection = $productCollection->getCollectionClone()
186                 ->removeAttributeSearch(['price.from', 'price.to']); 186                 ->removeAttributeSearch(['price.from', 'price.to']);
187         } 187         }
188  188 
189         $min = $productCollection->getMinPrice(); 189         $min = $productCollection->getMinPrice();
190         $max = $productCollection->getMaxPrice(); 190         $max = $productCollection->getMaxPrice();
191  191 
192         [$from, $to] = $this->_filterVal ?: [$min, $max]; 192         list($from, $to) = $this->_filterVal ?: [$min, $max];
193         $from = max(min($from, $max), $min); 193         $from = max(min($from, $max), $min);
194         $to   = min(max($to, $from), $max); 194         $to   = min(max($to, $from), $max);
195  195 
196         $item = $this->getItems()[0]; 196         $item = $this->getItems()[0];
197  197 
198         return [ 198         return [
199             'selectedFrom' => $from, 199             'selectedFrom' => $from,
200             'selectedTo'   => $to, 200             'selectedTo'   => $to,
201             'minValue'     => $min, 201             'minValue'     => $min,
202             'maxValue'     => $max, 202             'maxValue'     => $max,
203             'priceFormat'  => $this->_taxHelper->getPriceFormat(), 203             'priceFormat'  => $this->_taxHelper->getPriceFormat(),
204             'ajaxUrl'      => $item->getUrl() 204             'ajaxUrl'      => $item->getUrl()
205         ]; 205         ];
206     } 206     }
207  207 
208     /** 208     /**
209      * Get data array for building attribute filter items 209      * Get data array for building attribute filter items
210      * 210      *
211      * @return array 211      * @return array
212      * @throws LocalizedException 212      * @throws LocalizedException
213      * @throws StateException 213      * @throws StateException
214      */ 214      */
215     protected function _getItemsData() 215     protected function _getItemsData()
216     { 216     {
217         if (!$this->_moduleHelper->isEnabled()) { 217         if (!$this->_moduleHelper->isEnabled()) {
218             return parent::_getItemsData(); 218             return parent::_getItemsData();
219         } 219         }
220  220 
221         $attribute         = $this->getAttributeModel(); 221         $attribute         = $this->getAttributeModel();
222         $this->_requestVar = $attribute->getAttributeCode(); 222         $this->_requestVar = $attribute->getAttributeCode();
223  223 
224         /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ 224         /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
225         $productCollection = $this->getLayer()->getProductCollection(); 225         $productCollection = $this->getLayer()->getProductCollection();
226  226 
227         if ($this->_filterVal) { 227         if ($this->_filterVal) {
228             /** @type Collection $productCollectionClone */ 228             /** @type Collection $productCollectionClone */
229             $productCollection = $productCollection->getCollectionClone() 229             $productCollection = $productCollection->getCollectionClone()
230                 ->removeAttributeSearch(['price.from', 'price.to']); 230                 ->removeAttributeSearch(['price.from', 'price.to']);
231         } 231         }
232  232 
233         $facets = $productCollection->getFacetedData($attribute->getAttributeCode()); 233         $facets = $productCollection->getFacetedData($attribute->getAttributeCode());
234  234 
235         $data = []; 235         $data = [];
236         if (count($facets) >= 1) { // fix range of price with elasticsearch 236         if (count($facets) >= 1) { // fix range of price with elasticsearch
237             foreach ($facets as $key => $aggregation) { 237             foreach ($facets as $key => $aggregation) {
238                 $count = $aggregation['count']; 238                 $count = $aggregation['count'];
239                 if (strpos($key, '_') === false) { 239                 if (strpos($key, '_') === false) {
240                     continue; 240                     continue;
241                 } 241                 }
242                 $data[] = $this->prepareData($key, $count); 242                 $data[] = $this->prepareData($key, $count);
243             } 243             }
244         } 244         }
245  245 
246         return $data; 246         return $data;
247     } 247     }
248  248 
249     /** 249     /**
250      * @param string $key 250      * @param string $key
251      * @param int $count 251      * @param int $count
252      * 252      *
253      * @return array 253      * @return array
254      */ 254      */
255     private function prepareData($key, $count) 255     private function prepareData($key, $count)
256     { 256     {
257         [$from, $to] = explode('_', $key); 257         list($from, $to) = explode('_', $key);
258         if ($from === '*') { 258         if ($from === '*') {
259             $from = $this->getFrom($to); 259             $from = $this->getFrom($to);
260         } 260         }
261         if ($to === '*') { 261         if ($to === '*') {
262             $to = $this->getTo($to); 262             $to = $this->getTo($to);
263         } 263         }
264         $label = $this->_renderRangeLabel( 264         $label = $this->_renderRangeLabel(
265             empty($from) ? 0 : $from * $this->getCurrencyRate(), 265             empty($from) ? 0 : $from * $this->getCurrencyRate(),
266             empty($to) ? $to : $to * $this->getCurrencyRate() 266             empty($to) ? $to : $to * $this->getCurrencyRate()
267         ); 267         );
268         $value = (float) $from * $this->getCurrencyRate() . '-' . (float) $to * $this->getCurrencyRate(); 268         $value = (float) $from * $this->getCurrencyRate() . '-' . (float) $to * $this->getCurrencyRate();
269  269 
270         return compact('label', 'value', 'count', 'from', 'to'); 270         return compact('label', 'value', 'count', 'from', 'to');
271     } 271     }
272 } 272 }